/**
 * @program: LeetCode
 * @description: LeetCode : 566. 重塑矩阵
 * @author: WXY
 * @create: 2023-01-02 14:44
 * @Version 1.0
 **/
public class num566_matrixReshape {
    public static int[][] matrixReshape(int[][] mat, int r, int c) {
        int m = mat.length;
        int n = mat[0].length;
        if (r * c != m * n) {
            return mat;
        }
        int[][] ans = new int[r][c];
        for (int i = 0; i < m * n; i++) {
            ans[i / c][i % c] = mat[i / n][i % n];
        }
        return ans;
    }

}
